package com.witframework.baseapp.security.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.witframework.baseapp.security.Role;
import com.witframework.baseapp.security.service.RoleService;
import com.witframework.web.mvc.WebContext;

public class RoleController {
	@Autowired
	private RoleService roleService;
	public String executor(WebContext webContext) {
		List<Role> appList = roleService.pagedQuery(webContext.getFilter(), webContext.getPageSortModel("user"));
		webContext.setAttribute("dataList", appList);			
		return "//:view/role/index.jsp";
	}

	public String edit(WebContext webContext) {
		String[] ids = webContext.getSelItemList();
		if (ids != null && ids.length > 0) {
			Role app = (Role) roleService.get(ids[0]);
			webContext.setAttribute("data", app);			
		}
		return "//:view/role/update.jsp";
	}
	@Transactional
	public String store(WebContext webContext) {
		Role app = new Role();
		webContext.bindObject(app, "");
		webContext.validateObject("data", app, "//:view/role/update.jsp");
		roleService.saveOrUpdate(app);		
		webContext.setPageInfo("操作成功");		
		return "redirect://this";
	}
	@Transactional
	public String delete(WebContext webContext) {
		roleService.deleteAllByIds(webContext.getSelItemList());
		webContext.setPageInfo("操作成功");
		return "redirect://this";
	}

	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}
	
}
